package br.com.lucasddaniel.merchanmobile.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.com.lucasddaniel.merchanmobile.R;
import br.com.lucasddaniel.merchanmobile.bean.TuristaBean;

public class TuristasAdapter extends ArrayAdapter<TuristaBean> {
	private Context context = null;
	private List<TuristaBean> listTuristasBean = null;

	public TuristasAdapter(Context context, int resource,
			List<TuristaBean> listTuristasBean) {
		super(context, resource, listTuristasBean);
		this.context = context;
		this.listTuristasBean = listTuristasBean;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.row_turistas, parent,
				false);
		if (listTuristasBean != null && listTuristasBean.size() != 0) {
			TuristaBean turistasBean = listTuristasBean.get(position);
			if (turistasBean != null) {
				TextView txtViewNome = (TextView) rowView
						.findViewById(R.id_row_turistas.turistas_nome);
				TextView txtQuantidade = (TextView) rowView
						.findViewById(R.id_row_turistas.turistas_quantidade);
				TextView txtViewOperador = (TextView) rowView
						.findViewById(R.id_row_turistas.turistas_operador);
				TextView txtViewMotorista = (TextView) rowView
						.findViewById(R.id_row_turistas.turistas_motorista);
				ImageView imgChecked = (ImageView)rowView.findViewById(R.id_row_turistas.img);
				turistasBean.setImg(imgChecked);
				txtViewNome.setText(turistasBean.getNome());
				txtQuantidade.setText(turistasBean.getQuantidade()+"");
				txtViewMotorista.setText(turistasBean.getMotorista());
				txtViewOperador.setText(turistasBean.getOperador());
				if(turistasBean.isChecked()){
					turistasBean.getImg().setVisibility(View.VISIBLE);
				}else{
					turistasBean.getImg().setVisibility(View.INVISIBLE);
				}
			}
		}
		return rowView;
	}

	@Override
	public int getCount() {
		return super.getCount();
	}
}
